/*     */ package com.openbravo.pos.forms;
/*     */ 
/*     */ import com.openbravo.data.gui.JMessageDialog;
/*     */ import com.openbravo.data.gui.MessageInf;
/*     */ import com.openbravo.pos.util.Hashcypher;
/*     */ import java.awt.Component;
/*     */ import java.awt.Container;
/*     */ import java.awt.Dialog;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.FlowLayout;
/*     */ import java.awt.Frame;
/*     */ import java.awt.Insets;
/*     */ import java.awt.Toolkit;
/*     */ import java.awt.Window;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import javax.swing.ImageIcon;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JDialog;
/*     */ import javax.swing.JFrame;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JPasswordField;
/*     */ import javax.swing.JRootPane;
/*     */ import javax.swing.border.EmptyBorder;
/*     */ 
/*     */ public class JDlgChangePassword extends JDialog
/*     */ {
/*     */   private String m_sOldPassword;
/*     */   private String m_sNewPassword;
/*     */   private JLabel jLabel1;
/*     */   private JLabel jLabel2;
/*     */   private JLabel jLabel3;
/*     */   private JPanel jPanel1;
/*     */   private JPanel jPanel2;
/*     */   private JButton jcmdCancel;
/*     */   private JButton jcmdOK;
/*     */   private JPasswordField jtxtPasswordNew;
/*     */   private JPasswordField jtxtPasswordOld;
/*     */   private JPasswordField jtxtPasswordRepeat;
/*     */ 
/*     */   private JDlgChangePassword(Frame parent, boolean modal)
/*     */   {
/*  39 */     super(parent, modal);
/*     */   }
/*     */ 
/*     */   private JDlgChangePassword(Dialog parent, boolean modal) {
/*  43 */     super(parent, modal);
/*     */   }
/*     */ 
/*     */   private String init(String sOldPassword)
/*     */   {
/*  48 */     initComponents();
/*     */ 
/*  50 */     getRootPane().setDefaultButton(this.jcmdOK);
/*     */ 
/*  52 */     this.m_sOldPassword = sOldPassword;
/*  53 */     this.m_sNewPassword = null;
/*     */ 
/*  56 */     setVisible(true);
/*     */ 
/*  58 */     return this.m_sNewPassword;
/*     */   }
/*     */ 
/*     */   private static Window getWindow(Component parent)
/*     */   {
/*  63 */     if (parent == null)
/*  64 */       return new JFrame();
/*  65 */     if (((parent instanceof Frame)) || ((parent instanceof Dialog))) {
/*  66 */       return (Window)parent;
/*     */     }
/*  68 */     return getWindow(parent.getParent());
/*     */   }
/*     */ 
/*     */   public static String showMessage(Component parent, String sOldPassword)
/*     */   {
/*  74 */     Window window = getWindow(parent);
/*     */     JDlgChangePassword myMsg;
/*     */    // JDlgChangePassword myMsg;
/*  77 */     if ((window instanceof Frame))
/*  78 */       myMsg = new JDlgChangePassword((Frame)window, true);
/*     */     else {
/*  80 */       myMsg = new JDlgChangePassword((Dialog)window, true);
/*     */     }
/*  82 */     return myMsg.init(sOldPassword);
/*     */   }
/*     */ 
/*     */   private void initComponents()
/*     */   {
/*  92 */     this.jPanel2 = new JPanel();
/*  93 */     this.jcmdOK = new JButton();
/*  94 */     this.jcmdCancel = new JButton();
/*  95 */     this.jPanel1 = new JPanel();
/*  96 */     this.jLabel1 = new JLabel();
/*  97 */     this.jtxtPasswordOld = new JPasswordField();
/*  98 */     this.jLabel2 = new JLabel();
/*  99 */     this.jtxtPasswordNew = new JPasswordField();
/* 100 */     this.jtxtPasswordRepeat = new JPasswordField();
/* 101 */     this.jLabel3 = new JLabel();
/*     */ 
/* 103 */     setDefaultCloseOperation(2);
/* 104 */     setTitle(AppLocal.getIntString("title.changepassword"));
/* 105 */     setResizable(false);
/* 106 */     this.jPanel2.setLayout(new FlowLayout(2));
/*     */ 
/* 108 */     this.jcmdOK.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png")));
/* 109 */     this.jcmdOK.setText(AppLocal.getIntString("Button.OK"));
/* 110 */     this.jcmdOK.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent evt) {
/* 112 */         JDlgChangePassword.this.jcmdOKActionPerformed(evt);
/*     */       }
/*     */     });
/* 116 */     this.jPanel2.add(this.jcmdOK);
/*     */ 
/* 118 */     this.jcmdCancel.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png")));
/* 119 */     this.jcmdCancel.setText(AppLocal.getIntString("Button.Cancel"));
/* 120 */     this.jcmdCancel.addActionListener(new ActionListener() {
/*     */       public void actionPerformed(ActionEvent evt) {
/* 122 */         JDlgChangePassword.this.jcmdCancelActionPerformed(evt);
/*     */       }
/*     */     });
/* 126 */     this.jPanel2.add(this.jcmdCancel);
/*     */ 
/* 128 */     getContentPane().add(this.jPanel2, "South");
/*     */ 
/* 130 */     this.jPanel1.setLayout(null);
/*     */ 
/* 132 */     this.jPanel1.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
/* 133 */     this.jLabel1.setText(AppLocal.getIntString("label.passwordold"));
/* 134 */     this.jPanel1.add(this.jLabel1);
/* 135 */     this.jLabel1.setBounds(20, 20, 120, 14);
/*     */ 
/* 137 */     this.jPanel1.add(this.jtxtPasswordOld);
/* 138 */     this.jtxtPasswordOld.setBounds(140, 20, 180, 20);
/*     */ 
/* 140 */     this.jLabel2.setText(AppLocal.getIntString("label.passwordnew"));
/* 141 */     this.jPanel1.add(this.jLabel2);
/* 142 */     this.jLabel2.setBounds(20, 50, 120, 14);
/*     */ 
/* 144 */     this.jPanel1.add(this.jtxtPasswordNew);
/* 145 */     this.jtxtPasswordNew.setBounds(140, 50, 180, 20);
/*     */ 
/* 147 */     this.jPanel1.add(this.jtxtPasswordRepeat);
/* 148 */     this.jtxtPasswordRepeat.setBounds(140, 80, 180, 20);
/*     */ 
/* 150 */     this.jLabel3.setText(AppLocal.getIntString("label.passwordrepeat"));
/* 151 */     this.jPanel1.add(this.jLabel3);
/* 152 */     this.jLabel3.setBounds(20, 80, 120, 14);
/*     */ 
/* 154 */     getContentPane().add(this.jPanel1, "Center");
/*     */ 
/* 156 */     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
/* 157 */     setBounds((screenSize.width - 416) / 2, (screenSize.height - 205) / 2, 416, 205);
/*     */   }
/*     */ 
/*     */   private void jcmdCancelActionPerformed(ActionEvent evt)
/*     */   {
/* 163 */     dispose();
/*     */   }
/*     */ 
/*     */   private void jcmdOKActionPerformed(ActionEvent evt)
/*     */   {
/* 168 */     if (new String(this.jtxtPasswordNew.getPassword()).equals(new String(this.jtxtPasswordRepeat.getPassword()))) {
/* 169 */       if (Hashcypher.authenticate(new String(this.jtxtPasswordOld.getPassword()), this.m_sOldPassword)) {
/* 170 */         this.m_sNewPassword = Hashcypher.hashString(new String(this.jtxtPasswordNew.getPassword()));
/* 171 */         dispose();
/*     */       } else {
/* 173 */         JMessageDialog.showMessage(this, new MessageInf(-33554432, AppLocal.getIntString("message.BadPassword")));
/*     */       }
/*     */     }
/* 176 */     else JMessageDialog.showMessage(this, new MessageInf(-33554432, AppLocal.getIntString("message.changepassworddistinct")));
/*     */   }
/*     */ }

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.forms.JDlgChangePassword
 * JD-Core Version:    0.6.0
 */